﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GT.Framework.RabbitMQ.Core
{
    /// <summary>
    /// 发送消息
    /// </summary>
    public class DoRabbitMQPublish: DoRabbitMQBase
    {
        public string QueueName { get; private set; }
        public DoRabbitMQPublish(string queueName) {
            QueueName = queueName;

            // 创建一个消息队列
            Channel.QueueDeclare(queue: QueueName,
                 durable: false,
                 exclusive: false,
                 autoDelete: false,
                 arguments: null);
        }

        public void Publish(string message) {
            var body = Serialize(message);

            //向该消息队列发送消息message
            Channel.BasicPublish(
                exchange: "", 
                routingKey: QueueName, 
                mandatory: true, 
                basicProperties: null,
                body: body);
        }
    }
}
